package com.beerandjesus.sportofkings.handicapper.dao;

import com.beerandjesus.sportofkings.handicapper.model.JockeyPerformance;
import com.beerandjesus.sportofkings.handicapper.model.JockeyRatingThreshold;

import java.math.MathContext;
import java.util.List;

/**
 * Date: Jun 7, 2012
 * Time: 6:21:51 PM
 */
public interface JockeyDAO extends AbstractDAO {

    public static final String JOCKEY_RATING_THRESHOLD = "jockey_rating_threshold";
    public static final String JOCKEY_PERFORMANCE = "jockey_performance";
    public static final String JOCKEY_RATING_THRESHOLD_DEF = " (name varchar(100) not null unique, active_fl integer, " +
            "leading_threshold decimal(3,2), excellent_threshold decimal(3,2), good_threshold decimal(3,2))";
    public static final String JOCKEY_PERFORMANCE_DEF = " (name varchar(100) not null unique, win_ratio decimal(3,2))";
    public static final MathContext JOCKEY_STATS_MATH_CONTEXT = new MathContext(2);

    /**
     * Build (or rebuild) the jockey database from scratch
     *
     * @throws DAOException When something goes wrong
     */
    void buildDatabase() throws DAOException;

    /**
     * Get a count of rows in the jockey performance database
     *
     * @return int The row count
     * @throws DAOException When something goes wrong
     */
    int getJockeyPerformanceRowCount() throws DAOException;

    /**
     * Get all jockey rating thresolds
     *
     * @return All JockeyRatingThreshold
     * @throws DAOException When something goes wrong
     */
    List<JockeyRatingThreshold> getAllJockeyRatingThresholds() throws DAOException;

    /**
     * Save a JockeyRatingThreshold
     *
     * @param jrt The threshold
     * @throws DAOException When something goes wrong
     */
    void save(JockeyRatingThreshold jrt) throws DAOException;

    /**
     * Get a jockey rating threshold by its name
     *
     * @param name The name
     * @return The jockey rating threshold, or null if it does not exist
     * @throws DAOException When something goes wrong
     */
    JockeyRatingThreshold getJockeyRatingThresholdByName(String name) throws DAOException;

    /**
     * Delete a JockeyRatingThreshold
     *
     * @param thresh The threshold
     * @throws DAOException When something goes wrong
     */
    void delete(JockeyRatingThreshold thresh) throws DAOException;

    /**
     * Save a jockey performance
     *
     * @param perf The performance
     * @throws DAOException When something goes wrong
     */
    void save(JockeyPerformance perf) throws DAOException;

    /**
     * Get a jockey performance by jockey name
     *
     * @param name The jockey name
     * @return The jockey's performance
     * @throws DAOException When something goes wrong
     */
    JockeyPerformance getJockeyPerformanceByName(String name) throws DAOException;

    /**
     * Get the active JockeyRatingThreshold
     *
     * @return The threshold
     * @throws DAOException When something goes wrong
     */
    JockeyRatingThreshold getActiveJockeyRatingThreshold() throws DAOException;

    /**
     * Get all jockey performances
     *
     * @return All jockey performances
     * @throws DAOException When something goes wrong
     */
    List<JockeyPerformance> getAllJockeyPerformances() throws DAOException;
}
